import axios from "axios";
import Toast from "@/components/toast"

const instance =  axios.create({
  baseURL: 'https://cnodejs.org/api/v1',
  timeout: 10000,
})
instance.defaults.withCredentials = false;
// http request 拦截器
instance.interceptors.request.use(
  config => {
    return config
  },
  err => {
    return Promise.reject(err);
  });

instance.interceptors.response.use(
  res => {
    return res
  },
  err => {
    if (err.response && err.response.data.error_msg) {
      Toast(err.response.data.error_msg)
    } else {
      console.error(err)
    }
    return Promise.reject(err);
  }
)

export default instance